﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    /// <summary>
    /// 命令解析结果
    /// </summary>
    public class CommandParseResult: BaseResult<Command>
    {
        /// <summary>
        /// 命令的参数列表
        /// </summary>
        public Dictionary<string, string> Params { get; set; }


        public static CommandParseResult CreateFailInstance(string failMsg, int errorIndex = -1, string command = "")
        {
            CommandParseResult cpr = new CommandParseResult();
            cpr.Success = false;
            cpr.Code = BaseResultCode.CODE_ADD_FAILURE;
            if(errorIndex >= 0)
            {
                var space = "";
                for (int i = 0; i < errorIndex; i++) space += " "; 
                cpr.Description = $"{command}\r\n{space}^\r\n% ";
            }
            cpr.Description += failMsg;
            return cpr;
        }
        public static CommandParseResult CreateSuccessInstance(Command command, Dictionary<string, string> pars)
        {
            CommandParseResult cpr = new CommandParseResult();
            cpr.Success = true;
            cpr.Code = BaseResultCode.CODE_OK;
            cpr.Data = command;
            cpr.Params = pars;
            return cpr;
        }
    }
}
